import Vue from 'vue';
import Router from 'vue-router';
import home from './home';
// import test from './test';

Vue.use(Router);

const router = new Router({
    // mode: 'history',
    // base:'lucky',
    routes: [
        {
            path: '/',
            redirect: '/index'
        }, {
            path: '*',
            redirect: '/404',
            meta: {title: '默认为404页面'}
        }, {
            path: '/404',
            component: resolve => require(['../views/404.vue'], resolve),
            meta: {title: '页面没有找到'}
        }, {
            path: '/403',
            component: resolve => require(['../views/403.vue'], resolve),
            meta: {title: '没有权限'}
        }, {
            path: '/login',
            component: resolve => require(['../views/Login.vue'], resolve)
        }, {
            path: '/',
            component: resolve => require(['../views/Home.vue'], resolve),
            meta: {title: '自述文件'},
            children: [
                ...home
            ]
        },
    ]
});


// 使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
    next();
});


/**
 * 页面跳转之后处理
 */
router.afterEach((to, from, next) => {
    window.scrollTo(0, 0);      //使页面能返回顶部
});


export default router;
